package com.qinglei.recoup.longconn.entity;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
@Deprecated
public class GrayScaleDataBody extends BodyT {
    /**
     * 帧数位 uint32
     */
    private long frameNo;
    /**
     * 雷达原始数据 uint16 * N
     */
    private byte[] data;

    @Override
    public byte[] encode() {
        int length = 4;
        if (data != null) {
            length += data.length;
        }
        ByteBuf byteBuf = Unpooled.buffer(length);
        byteBuf.writeInt((int) this.getFrameNo());
        if (data != null) {
            byteBuf.writeBytes(data);
        }
        return byteBuf.array();
    }

    @Override
    public void decode(byte[] body) {
        ByteBuf byteBuf = Unpooled.wrappedBuffer(body);
        long frameNo = byteBuf.readUnsignedInt();
        this.setFrameNo(frameNo);

        int dataLength = byteBuf.readableBytes();
        byte[] data = new byte[dataLength];
        byteBuf.readBytes(data);
        this.setData(data);
    }
}